package com.qf.day05.homework;

import java.util.Arrays;
import java.util.Scanner;

public class UserUtils {
    User[] users={};
    int size=0;

    /**
     * 用户注册
     * @param userName
     * @param passWord
     * @return
     */
    public  boolean register(String userName, String passWord){
        //判断是否用户名存在
        for (int i = 0; i < size; i++) {
            if(userName.equals(users[i].userName)){
                return false;
            }
        }
        //如果数组长度不够,拷贝一个数组,数组长度增加
        if(size==users.length){
            users= Arrays.copyOf(users,users.length+5);
        }
        //创建对象
        User user=new User(userName,passWord);
        //将注册成功的用户名密码存进数组对象

        users[size]=user;
        //有效个数
        size++;
        return true;
    }
    public  boolean login(String userName,String passWord){
        for (int i = 0; i < size; i++) {
            if(userName.equals(users[i].userName)&&passWord.equals(users[i].password)){
                return true;
            }
        }
        return false;
    }
    
}
